/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package action.comment;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.Activity;
import po.Comment;
import po.User;
import service.ActivityService;
import service.OrgService;
/**
 *
 * @author HX
 */

public class DeleteCommentAction extends ActionSupport implements ServletRequestAware
{
    private ActivityService activityService;
    private HttpServletRequest request;
    private OrgService orgService;

     @Override
    public String execute()
     {
         int userId;
         int commentId;
         int activityId;
         int orgId;
         String msg;
         if (ActionContext.getContext().getSession().get("user") == null) {
            msg = "you should login first";
            request.setAttribute("msg", msg);
            return ERROR;
         }
         userId = ((User) ActionContext.getContext().getSession().get("user")).getId();
         if(request.getParameter("activityId")==null)
         {
             msg="no activity id!!!";
             request.setAttribute("msg", msg);
             return ERROR;
         }
         activityId = Integer.parseInt(request.getParameter("activityId"));
         if(request.getParameter("orgId")==null)
         {
             msg="no org id!!!";
             request.setAttribute("msg", msg);
             return ERROR;
         }
         orgId = Integer.parseInt(request.getParameter("orgId"));
         if(!orgService.isLeader(userId, orgId)){
             msg="you are not leader!!!";
             request.setAttribute("msg", msg);
             return ERROR;
         }
         commentId = Integer.parseInt(request.getParameter("commentId"));
         activityService.deleteComment(commentId);
         request.setAttribute("url", "viewComments.action?activityId=" + activityId + "&orgId=" + orgId);
         return SUCCESS;
     }

    public void setActivityService(ActivityService activityService)
    {
        this.activityService=activityService;
    }

    public ActivityService getActivityService()
    {
        return this.activityService;
    }

    public void setServletRequest(HttpServletRequest request)
    {
        this.request=request;
    }

    public OrgService getOrgService() {
        return orgService;
    }

    public void setOrgService(OrgService orgService) {
        this.orgService = orgService;
    }

}

